% -------------------------------------------------------------------------
% MAIN
% -------------------------------------------------------------------------
global GENERATION;
global MAX_GEN_STRUCTURE;

constants;
population = get_individuals();
GENERATION = 0;
MAX_GEN_STRUCTURE = 0;
max_vec = [];
mean_vec = [];
std_vec = [];
count = 1;

f = zeros(1, length(population));
for i = 1:length(population)
   f(i) = fitness(population{i});
end
fprintf('Best Net Fitness: %g\n\n', max(f));
previous_population = population;

while cut_criteria(GENERATION, population, previous_population, max(f))
    previous_population = population;
    individuals_for_reproduction = selection(population);
    new_individuals = reproduction(individuals_for_reproduction);
    population = replacement(population, new_individuals);
    GENERATION = GENERATION + 1;
    % -----------
    for i = 1:length(population)
        f(i) = fitness(population{i}); 
    end
    fprintf('Generacion: %d | Best Net Fitness: %g | Avg Nets Fitness: %g | Std Nets Fitness: %g\n', GENERATION, max(f), std(f), mean(f));
    % -----------
    max_vec(count) = max(f);
    mean_vec(count) = mean(f);
    std_vec(count) = std(f);
    count = count+1;
end

for i = 1:length(population)
   f(i) = fitness(population{i}); 
end
fprintf('\nBest Net Fitness: %g\n', max(f));
